package com.ljy.my_study.arthas;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;

public class ArthasTest {

    public static void main(String[] args) {
        testMultiThreads();
    }

    public static void testMultiThreads(){

        int length=50;
        CountDownLatch countDownLatch=new CountDownLatch(length);
        ExecutorService executorService=new ThreadPoolExecutor(length,length,20,
                TimeUnit.SECONDS,new LinkedBlockingDeque());

        AtomicBoolean atomicBoolean=new AtomicBoolean(true);
        Runnable task=()->{
          int count=15;
          while(atomicBoolean.get()){
              System.out.println(Thread.currentThread().getName()+"-->count:"+count);
              try {
                  Thread.sleep((long)(Math.random()*2_000));
                  count--;
                  if(count<0){
                      break;
                  }
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
          }
          countDownLatch.countDown();
        };
        for(int i=0;i<length;i++){
            executorService.submit(task);
        }
//        Thread.currentThread().setDaemon(true);
//        try {
//            Thread.sleep(60_000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
//        executorService.shutdown();
    }
}
